@extends('admin.admin')

@section('content')
        <!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        品牌管理
        <small>品牌列表</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="/admin"><i class="fa fa-dashboard"></i> 控制面板</a></li>
        <li ><a href="/admin/brand">品牌管理</a></li>
        <li class="active">品牌列表</li>
    </ol>
</section>

<!-- Main content -->
<section class="content">

    <div class="row">
        <div class="col-xs-12">

            <div class="box box-primary ">
                <div class="box-body table-responsive">
                    <a href="{{route('admin.brand.create')}}" class="btn btn-success"><i class="icon glyphicon glyphicon-plus"></i>添加</a>

                    {!! Form::model(@$brands,array('route' => 'admin.brand.index','method' => 'get','class'=>'form-search form-inline pull-right')) !!}
                    <div class="form-group">
                        {!! Form::text('brand_name',$search['brand_name'],['class'=>'form-control','placeholder'=>'品牌名称'])!!}
                    </div>
                    <button type="submit" class="btn btn-primary">搜索</button>
                    <button type="button" onclick="window.location.href='/admin/brand'" class="btn btn-default">重置</button>
                    {!! Form::close() !!}
                </div>
            </div><!-- end .box box-primary -->

            <div class="box box-primary">
                <div class="box-header">
                    <h3 class="box-title">品牌列表</h3>

                    <div class="box-tools pull-right">
                        <a href="{{route('admin.brand.create')}}" class="btn btn-box-tool"><i class="icon glyphicon glyphicon-plus"></i>添加</a>
                    </div>
                </div>
                <!-- /.box-header -->
                <div class="box-body table-responsive no-padding">
                    <table class="table table-hover">
                        <tr>
                            <th style="width: 80px;">ID</th>
                            <th style="width: 150px;">品牌名称</th>
                            <th>描述</th>
                            <th style="width: 80px;">推荐</th>
                            <th style="width: 150px;">操作</th>
                        </tr>
                        @foreach ($brands as $brand)
                            <tr>
                                <td>{{$brand->brand_id}}</td>
                                <td>{{$brand->brand_name}}</td>
                                <td>{{$brand->brand_desc}}</td>

                                <td class="is_recommend" id="{{$brand->brand_id}}" is_recommend="{{$brand->is_recommend}}">@if($brand->is_recommend==0)
                                        <i  class="glyphicon glyphicon-ok" title="推荐" style=" cursor: pointer;color: green;"></i>
                                    @else
                                        <i  class="glyphicon glyphicon-remove" title="取消推荐" style=" cursor: pointer;color: red;"></i>
                                    @endif
                                </td>


                                <td>
                                    <a href="{{Route('admin.brand.edit',$brand->brand_id)}}" type="button"
                                       class="btn  btn-default btn-xs"><i class="icon  glyphicon glyphicon-edit"></i> 修改</a>
                                    <button type="button" class="btn  btn-danger btn-xs" data-toggle="modal"
                                            data-target="#modal{{$brand->brand_id}}"><i
                                                class="icon  glyphicon glyphicon-remove"></i> 删除
                                    </button>

                                    <div id="modal{{$brand->brand_id}}" class="modal fade">
                                        <div class="modal-dialog">
                                            <div class="modal-content">
                                                <div class="modal-header">
                                                    <button type="button" class="close" data-dismiss="modal"
                                                            aria-label="Close"><span aria-hidden="true">&times;</span>
                                                    </button>
                                                    <h4 class="modal-title">删除警告:</h4>
                                                </div>
                                                <div class="modal-body">
                                                    <p>确认要删除品牌[{{$brand->brand_name}}]吗?</p>
                                                </div>
                                                <div class="modal-footer">
                                                    {!! Form::open(['route' => ['admin.brand.destroy', $brand->brand_id],'name'=>$brand->brand_name]) !!}
                                                    {!! Form::hidden('_method', 'DELETE') !!}
                                                    <button type="button" class="btn btn-default" data-dismiss="modal">
                                                        取消
                                                    </button>
                                                    <button type="button" class="btn btn-danger01" itemid="{{$brand->brand_id}}">删除</button>

                                                    {!!Form::close()   !!}
                                                </div>
                                            </div><!-- /.modal-content -->
                                        </div><!-- /.modal-dialog -->
                                    </div><!-- /.modal -->

                                </td>
                            </tr>
                        @endforeach

                    </table>
                </div>
                <!-- /.box-body -->
                <div class="box-footer">
                    <!-- 分页 -->
                    <div class="pull-right no-margin-pager">
                        {!! $brands->appends(['brand_name' => $search['brand_name']])->render() !!}
                    </div>
                </div>
                <!-- /.box-footer -->
            </div>
            <!-- /.box -->
        </div>
    </div>


</section>
<!-- /.content -->
<script>

        $('.btn-danger01').on('click',function(e){
            e.preventDefault();
            var id = $(this).attr("itemid");
            if(!id) return false;

            $.ajax({
                url:'/admin/brand/'+id+"?"+Math.random(),
                type:'delete',
                data:{id:id,'_token':'{{csrf_token()}}'},
                dataType:"json",
                success:function(result){

                    if(result.status){
                      window.location.reload();

                    }else{
                    alert(result.message);
                        window.location.reload();
                    }

                }

            });

        });


    </script>



    <script >
        $('.is_recommend').on('click',function(){
            var el = $(this);
            var id = el.attr('id');
            var url = "{{Route('admin.brand.toggleShow')}}";
            $.ajax({
                url:url+"/?id="+id,
                type:'get',
                dataType:'json',
                success:function(result){
                    if(result.info){
                        if(result.is_recommend==0){
                            el.find('.glyphicon').removeClass('glyphicon-remove');
                            el.find('.glyphicon').addClass('glyphicon-ok');
                            el.find('.glyphicon').css("color","green");

                        }else{
                            el.find('.glyphicon').removeClass('glyphicon-ok');
                            el.find('.glyphicon').addClass('glyphicon-remove');
                            el.find('.glyphicon').css("color","red");

                        }

                    }
                }
            });
        });

    </script>
<script>
    $('.btn-danger').on('click', function () {
        console.log('11');
    });
</script>
@endsection